package com.example.colorball;

import android.graphics.Color;
import android.util.Log;

public class ColorManager {

	private int color;
	private int mixture = Color.RED;

	public int getColor() {
		return color;
	}

	private static COLORS colors;

	public void Setup(boolean createdByCollision, int color1, int color2) {
		
		if (!createdByCollision) {
			colors = COLORS.RED;
			color = Color.RED;
		}
		
		else {
			
			Log.w(null, "bla " + color1);
			colorMix(color1, color2);
			
			colors = COLORS.MIXTURE;
			color = mixture;
		}
	}

	public void changeColor() {
		switch (colors) {

		case RED:
			colors = COLORS.GREEN;
			color = Color.GREEN;
			break;

		case GREEN:
			colors = COLORS.BLUE;
			color = Color.BLUE;
			break;

		case BLUE:
			colors = COLORS.MIXTURE;
			color = this.mixture;
			break;

		case MIXTURE:
			colors = COLORS.RED;
			color = Color.RED;
			break;
		}
	}

	public void colorMix(int color1, int color2) {
		int r1, g1, b1, r2, g2, b2;

		// Calcula os tons de RGB em cada cor
		r1 = Color.red(color1);
		g1 = Color.green(color1);
		b1 = Color.blue(color1);

		r2 = Color.red(color2);
		g2 = Color.green(color2);
		b2 = Color.blue(color2);

		// Divide cada tom por 2 e acha a mistura.
		int r3 = (r1 + r2) / 2;
		int g3 = (g1 + g2) / 2;
		int b3 = (b1 + b2) / 2;

		colors = COLORS.MIXTURE;
		mixture = Color.rgb(r3, g3, b3);
	}
}
